package com.sx.zongzhi.presenter;

import com.sx.zongzhi.MyApplication;
import com.sx.zongzhi.bean.AppealBean;
import com.sx.zongzhi.modle.ApiManager;
import com.sx.zongzhi.net.BaseCallBack;
import com.sx.zongzhi.net.BaseResult;
import com.sx.zongzhi.view.IAppealView;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by XZY on 2017/11/30.
 *获取诉求服务
 */
public class AppealPest {

    private IAppealView iAppealView;

    public AppealPest(IAppealView iAppealView) {
        this.iAppealView=iAppealView;
    }


    /**
     *
     * @param appealStateCode 诉求状态码:提交需获取的列表对应的数字到后台以获取对应列表数据,对应关系:
     *                        (50-待办列表,69-已办列表,70-已办结,90-历史遗留列表)
     * @param name 名称
     * @param startDate  开始时间
     * @param endDate 结束时间
     * @param place 事件发生地点
     * @param source  事件来源字典项id
     * @param type 事件类型字典项id
     * @param page 当前页
     * @param rows 当前多条
     *  @param orgId 组织id
     */
    public void getAppealList(String appealStateCode,String name,String startDate,
                              String endDate,String place,String source,String type,String orgId,
                              int page,int rows){
        Map<String,Object> map=new HashMap<>();
        map.put("sid", MyApplication.sid);
        map.put("appealStateCode", appealStateCode);
        map.put("mobileAppealSearchVo.name",name);
        map.put("mobileAppealSearchVo.startDate",startDate);
        map.put("mobileAppealSearchVo.endDate", endDate);
        map.put("mobileAppealSearchVo.place", place);
        map.put("mobileAppealSearchVo.source", source);
        map.put("mobileAppealSearchVo.type",type);
        map.put("mobileAppealSearchVo.orgId",orgId);
        map.put("page", page);
        map.put("rows", rows);
        new ApiManager().getAppealList(map, new BaseCallBack<BaseResult<AppealBean>>() {
            @Override
            public void onSuccess(BaseResult<AppealBean> response) {
                iAppealView.getAppealList(response.getData());
            }
            @Override
            public void onFailures(String message) {
                iAppealView.showError(message);
            }
        });
    }

    /**
     *  诉求服务 受理/更多
     * @param appealId 诉求事件id
     * @param stepRecordId 事件步骤id
     * @param operationCode 操作码:提交操作对应的数字到后台以进行对应操作,对应关系:(2049-受理,3010-加急)
     * @param content 意见: (1010-普通督办,1030-黄牌督办,1050-红牌督办,3030-批示)
     */
    public void acceptAppeal(String appealId,String stepRecordId,String operationCode,String content){
        Map<String,Object> map=new HashMap<>();
        map.put("sid", MyApplication.sid);
        map.put("appealId",appealId);
        map.put("stepRecordId",stepRecordId);
        map.put("operationCode",operationCode);
        map.put("content",content);
        new ApiManager().acceptAppeal(map, new BaseCallBack<BaseResult<Boolean>>() {
            @Override
            public void onSuccess(BaseResult<Boolean> response) {
                if (response.data){
                    iAppealView.accept("事件受理成功");
                }
            }
            @Override
            public void onFailures(String message) {
                iAppealView.showError(message);
            }
        });
    }
}
